<template>
  <div style="font-size:15px;font-weight: 600;margin-left: 60px;">订单详情</div>
  <div>
    <el-tabs v-model="activeTab" style="margin-left: 60px;margin-top: 20px;">
        <el-form label-width="110px" style="margin-top: 20px;margin-left: -32px;" :model="state.dataForm"
                 ref="dataFormRef">
          <el-row>
            <el-col>
              <el-form-item label="订单编号" prop="orderNum">
                <el-text>{{ state.dataForm.orderNum }}</el-text>
              </el-form-item>
            </el-col>
            <el-col>
              <el-form-item label="账号" prop="userPhone">
                <el-text>{{ state.dataForm.userPhone }}</el-text>
              </el-form-item>
            </el-col>
            <el-col>
              <el-form-item label="公司名称" prop="company">
                <el-text>{{ state.dataForm.company }}</el-text>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
    </el-tabs>
  </div>
  <el-table :header-cell-style="{ 'background': '#eef1f6', 'color': '#1f2d3d', 'border-color': '#dfe6ec' }"
            v-loading="state.dataListLoading" :data="state.dataList">
    <el-table-column align="center" prop="productName" label="产品名称" width="180" show-overflow-tooltip></el-table-column>
    <el-table-column align="center" prop="tidName" label="配置详情" width="280" show-overflow-tooltip></el-table-column>
    <el-table-column align="center" prop="payType" label="支付方式" width="180" show-overflow-tooltip></el-table-column>
    <el-table-column align="center" prop="updateTime" label="支付时间" width="180" show-overflow-tooltip></el-table-column>
    <el-table-column align="center" prop="productQuantity" label="数量" width="80" show-overflow-tooltip></el-table-column>
    <el-table-column align="center" prop="payAmount" label="有效时长（月）" width="180" show-overflow-tooltip></el-table-column>
    <el-table-column align="center" prop="updateTime" label="查询次数" width="100" show-overflow-tooltip></el-table-column>
    <el-table-column align="center" prop="payAmount" label="支付金额" width="100" show-overflow-tooltip></el-table-column>
  </el-table>
  <div class="foot">
    <el-button type="primary" @click="cancel()">{{ $t("confirm") }}</el-button>
  </div>
</template>

<script lang="ts" setup>
import baseService from "@/service/baseService";
import { ElMessage } from "element-plus";
import { useRoute, useRouter } from 'vue-router';
import useView from "@/hooks/useView";
import { reactive, ref, toRefs, onMounted, computed } from "vue";
import { useI18n } from "vue-i18n";

const { t } = useI18n();

const router = useRouter();
const route = useRoute();
const orderNum = route.query.orderNum;

const dataFormRef = ref();
const view = reactive({
  dataForm: {
    orderNum: orderNum,
    userPhone: '',
    company: '',
  },
  dataList: [] as any[],
  dataListLoading: false
});
const state = reactive({ ...useView(view), ...toRefs(view) });
// tab切换显示
const activeTab = ref('tab1');

const init = () => {
  // 重置表单数据
  if (dataFormRef.value) {
    dataFormRef.value.resetFields();
  }

  if (orderNum) {
    baseService.get("/noc/nocorder/orderNum/" + orderNum).then((res) => {
      console.log("----------------------",res.nocOrder);
      Object.assign(state.dataForm, res.nocOrder);
      state.dataList = [res.nocOrder];
      console.log("----------------------",state.dataList)
    });
  }
};

// 图片输入框引用，指定类型并初始化为null
const imageInput = ref<HTMLInputElement | null>(null);

onMounted(() => {
  const inputElement = document.querySelector('input[type="file"]');
  if (inputElement) {
    try {
      imageInput.value = inputElement as HTMLInputElement;
    } catch (error) {
      console.error("获取input元素时出错:", error);
    }
  }
});

const cancel = () => {
  const rawFrom = route.query.from;
  const from = Array.isArray(rawFrom) ? rawFrom[0] : rawFrom || '/program/nocorder-list';
  router.push(from as string);
  // 关闭当前标签页（需确保useView hook已正确配置）
  state.closeCurrentTab();
};
// 页面进入执行
init();
</script>

<style lang="scss" scoped>
.el-input {
  width: 224px;
  height: 32px;
  opacity: 1;
  border-radius: 5px;
  background: rgba(255, 255, 255, 1);
}

.el-select {
  width: 224px;
  height: 32px;
  opacity: 1;
  border-radius: 5px;
  background: rgba(255, 255, 255, 1);
}

.form {
  display: flex;
  justify-content: space-between;
}

.image-upload-container {
  width: 511px;
  border: 1px dashed #ccc;
  border-radius: 6px;
  padding: 10px;
}

.upload-tip {
  font-size: 13px;
  color: rgba(168, 171, 178, 1);
  margin-bottom: 10px;
}

.tip-text {
  color: #999;
  font-size: 14px;
}

.upload-dragger {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}


.upload-over-tip {
  color: #999;
  text-align: center;
}

.quxiao {
  border-radius: 5px;
  background: rgba(239, 244, 255, 1);
  color: rgba(22, 119, 255, 1);
  border: 1px solid rgba(22, 119, 255, 1);
}

.foot {
  display: flex;
  justify-content: end;
  position: absolute;
  bottom: 50px;
  right: 50px;
}

.add-button {
  width: 100px;
  height: 32px;
  padding: 10px 20px;
  background-color: rgba(22, 119, 255, 1);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  margin-bottom: 20px;
}

.add-button:hover {
  background-color: rgba(22, 119, 255, 1);
}

.model-container {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

.model-item {
  display: flex;
  align-items: center;
}

.model-select {
  padding: 8px;
  margin-right: 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
}

.model-input {
  padding: 8px;
  margin-right: 10px;
  border-radius: 5px;
  width: 156px;
  height: 32px;
  background: rgba(255, 255, 255, 1);
  border: 1px solid rgba(199, 199, 199, 1);
}

.model-input:focus {
  border: 0px;
  /* 获得焦点时边框颜色改为蓝色 */
  background: rgba(240, 245, 255, 1);
  color: rgba(22, 119, 255, 1);
  outline: none;
  /* 去除默认的焦点轮廓 */
}

.remove-button {
  padding: 8px 12px;
  background-color: #f44336;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.uploaded-image {
  width: 120px;
  height: 120px;
  object-fit: cover;
}

.brand-upload {
  display: block;
}

.upload-box {
  width: 100px;
  height: 100px;
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: border-color 0.3s;
}

.upload-box:hover {
  border-color: #409EFF;
}

.upload-box .icon {
  width: 32px;
  height: 32px;
}



// 产品图片/视频
.image-upload-section {
  display: flex;
  margin-bottom: 20px;
}

.image-upload-label {
  width: 50px;
}

.video-upload-section {
  display: flex;
}

.video-upload-label {
  width: 50px;
}

:deep(.el-upload--picture-card) {
  // background-repeat: no-repeat;
  // background-image: url(../../assets/images/upload.png);
  width: 80px !important;
  height: 80px !important;
}

.attribute-group {
  width: 684px;
  height: 100%;
  padding: 20px;
  border: 1px dashed rgba(31, 31, 31, 0.36);
  border-radius: 18px;
  margin-bottom: 38px;

}

.attribute-group-input {
  width: 492px;
  height: 32px;
}
.reject{
  margin-top: 20px;
  margin-left: 60px;
  height: 92px;
  border-radius: 6px;
  background-color: rgba(255,255,255,1);
  border: 1px solid rgba(187,187,187,1);
}
.reject span{
  font-weight: 600;
  margin-left: 30px;
  line-height: 92px;
  font-size: 16px;
}

</style>
